package com.hello.sky.controller.admin;

import com.hello.sky.model.dto.SetmealDTO;
import com.hello.sky.model.dto.SetmealPageQueryDTO;
import com.hello.sky.model.vo.SetmealVO;
import com.hello.sky.result.PageResult;
import com.hello.sky.result.Result;
import com.hello.sky.service.SetmealService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 套餐 前端控制器
 * </p>
 *
 * @author D
 */
@Slf4j
@RestController
@RequestMapping("/admin/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService  setmealService;

    @Operation(summary = "新增套餐")
    @PostMapping
    public Result addSetmal(@RequestBody SetmealDTO dto){
        setmealService.addSetmeal(dto);
        return Result.success();
    }

    @Operation(summary = "套餐分页查询")
    @GetMapping("/page")
    public Result<PageResult> getPage(SetmealPageQueryDTO dto){
        PageResult page = setmealService.getPage(dto);
        return Result.success(page);
    }

    @Operation(summary = "根据id查询套餐")
    @GetMapping("/{id}")
    public Result getPage(@PathVariable("id") Long id){
        SetmealVO setmealVO = setmealService.getSetmealByIdResVo(id);
        return Result.success(setmealVO);
    }

    @Operation(summary = "修改套餐")
    @PutMapping
    public Result updateSetmealWithDishAndCategory(@RequestBody SetmealDTO dto){
        setmealService.updateSetmealWithDishAndCategory(dto);
        return Result.success();
    }

    @Operation(summary = "套餐起售、停售")
    @PostMapping("/status/{status}")
    public Result updateSetmealStatus(@RequestParam("id") Long id, @PathVariable("status") Integer status){
        setmealService.updateSetmealStatus(id, status);
        return Result.success();
    }

    @Operation(summary = "批量删除套餐")
    @DeleteMapping
    public Result delSetmeaByIds(@RequestParam("ids") List<Long> ids){
        setmealService.delSetmeaByIds(ids);
        return Result.success();
    }
}
